package com.cskaoyan.controller.wechat;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.user.User;
import com.cskaoyan.service.OrderService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: Li Qing
 * @Create: 2020/5/5 12:02
 * @Version: 1.0
 */
@RestController
@RequestMapping("wx/user")
public class WxUserController {
    @Autowired
    OrderService orderService;

    @GetMapping("index")
    public BaseRespVo getUserIndex() {
        Subject subject = SecurityUtils.getSubject();
        User user = (User) subject.getPrincipal();
        Integer userId = user.getId();
        Long uncomment = orderService.queryUncommentOrderNum(userId);
        Long unpaid = orderService.queryUnPaidOrderNum(userId);
        Long unrecv = orderService.queryUnReceiveOrderNum(userId);
        Long unship = orderService.queryUnShipOrderNum(userId);
        Map<String, Object> map = new HashMap<>();
        map.put("uncomment", uncomment);
        map.put("unpaid", unpaid);
        map.put("unrecv", unrecv);
        map.put("unship", unship);
        Map<String, Object> result = new HashMap<>();
        result.put("order", map);
        return new BaseRespVo(0, result, "成功");
    }

}
